package com.p2p.base.exception;

import java.text.MessageFormat;
import java.util.Properties;
import java.util.ResourceBundle;

import org.springframework.context.i18n.LocaleContextHolder;

import com.p2p.base.util.Const;

/**
 * 异常处理
 * @author <a href="mailto:liyang@yiqihao.com">李阳</a>
 * @version 1.0
 */
@Deprecated
public class BusinessException extends RuntimeException{

	private static final long	serialVersionUID	= 665112595508596601L;

	private String					errorCode;

	private Object[]			args;

	private String				message;
	
	static Properties msgprop = new Properties(); 
	static boolean hasInit = false;

	private BusinessException	linkedException;

	public BusinessException(String errorCode){
		super();
		this.errorCode = errorCode;
	}

	public BusinessException(String errorCode, Object... args){
		super();
		this.errorCode = errorCode;
		this.args = args;
	}

	public BusinessException(String errorCode, String message){
		this.errorCode = errorCode;
		this.message = message;
	}

	public String getErrorCode(){
		return errorCode;
	}

	public void setErrorCode(String errorCode){
		this.errorCode = errorCode;
	}

	public Object[] getArgs(){
		return args;
	}

	public void setArgs(Object[] args){
		this.args = args;
	}

	@Override
	public String getMessage(){
		return message;
	}

	public void setMessage(String message){
		this.message = message;
	}

	public BusinessException getLinkedException(){
		return linkedException;
	}

	public void setLinkedException(BusinessException linkedException){
		this.linkedException = linkedException;
	}
	
	public String getI18NMessage() {
		String key = ExceptionResolver.BUSINESS_EXCEPTION_PREFIX + getErrorCode();
		String msg = ResourceBundle.getBundle(Const.ERR_MSG, LocaleContextHolder.getLocale()).getString(key);
		return MessageFormat.format(msg, args);
	}
}
